package com.wlyuan.open.domain.source;

import com.wlyuan.core.domain.valueobj.TenantId;
import com.wlyuan.core.domain.valueobj.UserId;
import com.wlyuan.core.exception.AssertUtils;
import com.wlyuan.core.exception.ValueError;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author yuanzheng
 */
@Data
@RequiredArgsConstructor
@AllArgsConstructor
public class SourceRelation implements Serializable {
    private static final long serialVersionUID = -6492368073456978806L;
    @ApiModelProperty("sourceKey")
    private String sourceKey;

    @ApiModelProperty("类型")
    private SourceClass sourceClass;

    @ApiModelProperty("租户ID")
    private TenantId tenantId;

    @ApiModelProperty("创建人ID")
    private UserId createBy;

    @ApiModelProperty("创建时间")
    private LocalDateTime createAt;

    @ApiModelProperty("目标ID")
    private Long targetId;

    private LocalDateTime updateAt;

    private UserId updateBy;

    public SourceRelation relate(Long targetId, UserId userId) {
        AssertUtils.assertNotNull(targetId, new ValueError("targetId不能为空"), this);
        this.targetId = targetId;
        this.updateBy = userId;
        return this;
    }

    public SourcePattern getPattern() {
        return new SourcePattern(sourceKey, sourceClass, tenantId);
    }
}
